package com.ceba.test.modules.email.entity;

import java.net.URL;

import org.apache.commons.lang.StringUtils;

import com.ceba.test.base.enums.FileTypeEnum;

/**
 * 邮件关联的文件：附件，html内嵌文件：图片 
 * @author Administrator
 */
public class EmailRelationFile {
	
	private String name;//文件名称 
	private String path;//绝对路径                 注:HTML图片文件必须 与 src 相同 
	private URL url;//url
	private String description;//文件描述
	private String charset;//编码 默认编码UTF-8
	private FileTypeEnum fileTypeEnum;
	public EmailRelationFile(){
		this.charset="UTF-8";
	}
	
	
	public EmailRelationFile(String name,String path,FileTypeEnum fileTypeEnum){
		this.charset="UTF-8";
		this.name=name;
		this.path=path;
		this.fileTypeEnum=fileTypeEnum;
	}
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public URL getUrl() {
		return url;
	}
	public void setUrl(URL url) {
		this.url = url;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getCharset() {
		return charset;
	}
	public void setCharset(String charset) {
		this.charset = charset;
	}
	public FileTypeEnum getFileTypeEnum() {
		return fileTypeEnum;
	}
	public void setFileTypeEnum(FileTypeEnum fileTypeEnum) {
		this.fileTypeEnum = fileTypeEnum;
	}
	@Override
	public String toString() {
		return "EmailRelationFile [name=" + name + ", path=" + path + ", url=" + url + ", description=" + description
				+ ", charset=" + charset + ", fileTypeEnum=" + fileTypeEnum + "]";
	}
	public void valid() throws Exception{
		if(fileTypeEnum == null){
			throw new NullPointerException("fileTypeEnum:邮件文件类型不能为空");
		}
		
		if(FileTypeEnum.ATTACHMENT==fileTypeEnum){
			if(StringUtils.isEmpty(name)){
				throw new NullPointerException("name:附件文件名不能为空");
			}
		}else if(FileTypeEnum.INLINE==fileTypeEnum){
			
		}else if(FileTypeEnum.HTML==fileTypeEnum){
			
		}
		
		if(url==null && StringUtils.isEmpty(path)){
			throw new NullPointerException("URL 和  文件路径  必须要有 一个");
		}
	}
	
}
